package cn.itsource.product.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.product.domain.Product;
import cn.itsource.product.domain.ProductDetail;
import cn.itsource.product.mapper.ProductDetailMapper;
import cn.itsource.product.mapper.ProductMapper;
import cn.itsource.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductDetailMapper productDetailMapper;

    @Autowired
    private ProductMapper productMapper;

    @Override
    public void add(Product product) {
        product.setState(0);
        product.setSalecount(0L);
        //1.先保存product  返回新增数据的主键
          super.add(product);

        ProductDetail detail = product.getDetail();
        detail.setProduct_id(product.getId());
        //2. 保存productDetail
        productDetailMapper.save(detail);

    }

    @Override
    public void onSale(Long[] ids) {
        productMapper.onSale(ids);
    }
}
